<?php
/**
 * @author Feng
 * @date 2012-7-6
 */
class controller_admin_resource_file extends system_user_controller_panel {
	
	private $concept = null;
	public function init() {
		if(!parent::init()) {
			return ;
		}
		$this->concept = new resource_file_concept();
		$this->_crumbs()->addPage(system_nav_page::create($this->language('Resource'))->setRoute('resource/index'));
		$this->_crumbs()->addPage(system_nav_page::create($this->language('Files'))->setRoute('resource/file/index'));
	}
		
	public function action_index() {
		$this->_goRoute('resource/file/list');
		$this->render();
	}
	
	public function action_list() {		
		$adapter = new system_paginator_adapter_concept($this->concept);
		$adapter->setCurrentPageNumber(intval($this->_param('page', 1)));
		
		$this->view->order = $order = strtolower($this->_get('order'));
		$keyword = trim($this->_get('keyword'));
		if($keyword == self::$_keyword) $keyword = '';
		if($keyword) {
			$adapter->where("`hash` LIKE ?", "%$keyword%");
		}
		if(1 && $_type = trim($this->_get('type'))) {
			try {
				$type = new resource_file_type($_type);
				$adapter->where("`type` = '{$type->getId()}'");
			} catch (Exception $e) {
				
			}
		}
		
		$_order = array("lastupdate DESC");
		if($order) {
			$this->view->sort = $sort = intval($this->_get('sort'));
			$_sort = !$sort ? 'DESC' : 'ASC';
			$_order = array("$order $_sort");
		}
		$adapter->setLimit(30);
		$adapter->order($_order);
		$this->view->list = new system_paginator($adapter);
		$this->_crumbs()->addPage(system_nav_page::create($this->language('List'))->setRoute('resource/file/list'));
		$this->render();
	}
}
